using System.Collections.Generic;
using Headsight.BPMN2WF.BPMN.Model;
using Headsight.BPMN2WF.Testing.TestObjCtors;
using Headsight.BPMN2WF.Transformation;
using Headsight.BPMN2WF.Transformation.Transformers.NoGoodName;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;

namespace Headsight.BPMN2WF.WF.Simplification
{
    [TestClass]
    public class BPMN2WFTransformationSimplifierTest : BPMN2WFTransformationDelegateBaseImplTestFixture<BPMN2WFTransformationSimplifier>
    {
        private IBPMN2WFTransformationContext _ctx;
        private BPMNFlowNode _flowNode;
        private BPMNTransformationResult _result;
        private BPMNTransformationResult _result1;
        private BPMNTransformationResult _result2;

        protected override BPMN2WFTransformationSimplifier  CreateSut(IBPMN2WFTransformation @delegate)
         {
            _ctx = new BPMN2WFTransformationContextCtor().Create();
            _flowNode = new BPMNFlowNodeCtor().Create();

            _result = new BPMNTransformationResultCtor().Create();
            _result1 = new BPMNTransformationResultCtor().Create();
            _result2 = new BPMNTransformationResultCtor().Create();

            return new BPMN2WFTransformationSimplifier(@delegate);
        }

        [TestMethod]
        public void Transform()
        {
            var simplifier1 = MockRepository.GenerateStub<IWFSimplifier>();
            var simplifier2 = MockRepository.GenerateStub<IWFSimplifier>();
            var simplifier3 = MockRepository.GenerateStub<IWFSimplifier>();

            _sut = new BPMN2WFTransformationSimplifier(_delegate,
                                                       new List<IWFSimplifier> {simplifier1, simplifier2, simplifier3});

            _delegate.Expect(x => x.Transform(_ctx, _flowNode)).Return(_result);
            simplifier1.Expect(x => x.Probe(_ctx, _result)).Return(true);
            simplifier1.Expect(x => x.Simplify(_ctx, _result)).Return(_result1);
            simplifier2.Expect(x => x.Probe(_ctx, _result1)).Return(false);
            simplifier3.Expect(x => x.Probe(_ctx, _result1)).Return(true);
            simplifier3.Expect(x => x.Simplify(_ctx, _result1)).Return(_result2);

            Assert.AreSame(_result2, _sut.Transform(_ctx, _flowNode));
        }
    }
}